package folder.model.network;

import java.util.List;

import folder.model.link.Link;
import folder.model.node.Node;
import folder.model.node.PathsNodeSource;

public class NetworkPaths
{
	private List< Node > nodes;
	public List< Node > getNodes(){ return this.nodes; }
	
	private List< Link > links;
	public List< Link > getLinks(){ return this.links; }
	
	private PathsNodeSource pathsNodeSource;
	
	public static NetworkPaths networkPaths( Network network )
	{
		return new NetworkPaths( network );
	}
	
	public NetworkPaths( Network network )
	{
		this.nodes = network.getNodes();
		this.links = network.getLinks();
		this.pathsNodeSource = PathsNodeSource.pathsNodeSource( nodes, links );
	}
	
	// Paths
		
	public void setPathsNodes( List< Node > nodesSource )
	{
		for( Node nodeSource: nodesSource )
			this.setPathsNode( nodeSource );
	}
	
 	public void setPathsNode( Node nodeSource )
	{
 		pathsNodeSource.setPathsNodeSource( nodeSource );
 		pathsNodeSource.putDelayToNodeTarget( nodeSource );		
		pathsNodeSource.putLinksToNodeTarget( nodeSource );
	}
 	
 	// Characteristics
 	
	public void setPathsNodes()
	{
		for( Node nodeSource: this.nodes )
			this.setPathsNode( nodeSource );
		
		this.setCharacteristics();
	}
 	
 	private void setCharacteristics()
 	{
 		this.setNumberPathsLinks();
 		this.setNumberPathsNodes();
 		
 		this.setDelayToNodeTargetLongest();
 		this.setDelayToNodeTargetMean();
 		
 		this.setAbw();
 	}
 	
	private void setNumberPathsLinks()
    {
    	for( Link link: links )
    		link.resetNumberPaths();
    	
		for( Node nodeA: nodes )
			for( Node nodeB: nodes )
			{
				List< Link > linksToNodeTarget = nodeA.getLinksToNodeTarget( nodeB );
				
				for( Link linkToNodeTarget: linksToNodeTarget )
					linkToNodeTarget.incrementNumberPaths();
			}
    }
 	
 	private void setNumberPathsNodes()
 	{
 		for( Node node: nodes )
 			node.setNumberPaths();
 	}
	 	
 	private void setDelayToNodeTargetLongest()
 	{
 		for( Node node: nodes )
 			node.setDelayToNodeTargetLongest();
 	}
 	
 	private void setDelayToNodeTargetMean()
 	{
 		for( Node node: nodes )
 			node.setDelayToNodeTargetMean();
 	}
 	
 	private void setAbw()
 	{
 		for( Node node: nodes )
 			node.setAbw();
 	}
 	
}
